package com.insurance.modules.partner.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.insurance.common.enums.DeleteFlagEnum;
import com.insurance.entity.PartnerRoleEntity;
import com.insurance.modules.sys.controller.AbstractController;
import com.insurance.service.PartnerRoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.R;



/**
 * 合作方角色
 *
 * @date 2021-02-27 15:51:21
 */
@RestController
@RequestMapping("partner/partnerrole")
public class PartnerRoleController extends AbstractController {

    @Autowired
    private PartnerRoleService partnerRoleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("partner:partnerrole:list")
    public R list(@RequestParam Map<String, Object> params, PartnerRoleEntity partnerRoleEntity){
        QueryWrapper<PartnerRoleEntity> queryWrapper = partnerRoleService.getQueryWrapper(partnerRoleEntity);
        PageUtils page = partnerRoleService.queryPage(params, queryWrapper);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{roleId}")
    @RequiresPermissions("partner:partnerrole:info")
    public R info(@PathVariable("roleId") String roleId){
		PartnerRoleEntity partnerRole = partnerRoleService.getById(roleId);
        return R.ok().put("partnerRole", partnerRole);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("partner:partnerrole:save")
    public R save(@RequestBody PartnerRoleEntity partnerRole){
        partnerRole.setRoleId(UUID.randomUUID().toString().replaceAll("-", ""));
        partnerRole.setUpdateTime(new Date());
        partnerRole.setUpdatePersonId(getUserIdStr());
        partnerRole.setUpdatePersonName(getUserName());
        partnerRole.setDeleteFlag(String.valueOf(DeleteFlagEnum.UN_DELETE.getCode()));
		partnerRoleService.save(partnerRole);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("partner:partnerrole:update")
    public R update(@RequestBody PartnerRoleEntity partnerRole){
        partnerRole.setUpdateTime(new Date());
        partnerRole.setUpdatePersonId(getUserIdStr());
        partnerRole.setUpdatePersonName(getUserName());
		partnerRoleService.updateById(partnerRole);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("partner:partnerrole:delete")
    public R delete(@RequestBody String[] roleIds){
        PartnerRoleEntity partnerRole = new PartnerRoleEntity();
        partnerRole.setUpdateTime(new Date());
        partnerRole.setUpdatePersonId(getUserIdStr());
        partnerRole.setUpdatePersonName(getUserName());
        partnerRole.setDeleteFlag(String.valueOf(DeleteFlagEnum.DELETE.getCode()));
		partnerRoleService.removeBatch(Arrays.asList(roleIds), partnerRole);
        return R.ok();
    }

}
